/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-05-16
 * Time: 23:04
 */
public class removeElement_2 {
    public static int removeElement(int[] nums, int val) {
        int left=0;
        int right=nums.length-1;
        while(left<=right){
            if (nums[left]==val&&nums[right]!=val){
                int tmp=nums[left];
                nums[left]=nums[right];
                nums[right]=tmp;
                right--;
            }
            if (nums[left]!=val){
                left++;
            }
            if (nums[right]==val){
                right--;
            }
        }
        return left;
    }
    public static void main(String[] args) {
        int[] nums=new int[]{2,2,3};
        int c=removeElement(nums,2);
        for (int i=0;i<c;i++){
            System.out.print(nums[i]+"  ");
        }
    }
}
